/* dashed line */
package renders.edge.arrows
{
	import flash.display.Graphics;
	import renders.edge.ExtendedEdge;
	
	public class DashedBody implements IArrowBodyDrawer
	{
		
		private var _g:Graphics;
		private var _drawer:ExtendedEdge; 
		private var threshold:Number;
		private var _color:uint;
		private var _alpha:Number;
		
		
		public function DashedBody()
		{
		}
		
		public function drawLine(g:Graphics, d:ExtendedEdge,t:Number,color:uint,alpha:Number, x1:Number, y1:Number, x2:Number, y2:Number):void
		{
			 _g = g
			 _drawer = d;
			 _color = color;
			 _alpha = alpha;
			 threshold = t;
			 var range:Number = Math.sqrt(Math.pow(x1-x2,2) + Math.pow(y1-y2,2));
			 subDrawLine(x1,y1,x2,y2,range); 
			
		}
		private function subDrawLine(x1:Number, y1:Number, x2:Number, y2:Number, d:Number):void
		{
			
			var mX:Number = (x1+x2)/2;
			var mY:Number = (y1+y2)/2;
			d = d/2;
			if (d<threshold)
			{
				drawSimpleLine(x1,y1,mX,mY);//one time
				//drawSimpleLine(mX,mY,x2,y2);//over two time
			}
			else
			{
				subDrawLine(x1,y1,mX,mY,d);
				subDrawLine(mX,mY,x2,y2,d);
			}
			 
		}
		
		private function drawSimpleLine(x1:Number, y1:Number, x2:Number, y2:Number):void
		{
			
			//line :
			_g.lineStyle(1, _color, _alpha);
			_drawer.move(_g, x1, y1);
			_drawer.line(_g, x2, y2);
		} 

	}
}